<?php
App::uses('AppModel', 'Model');
/**
 * Index Model
 *
 */
class Index extends AppModel {

function afterFind($results, $primary=false) 
 { 
  foreach ($results as $key => $val) 
  { 
   if (isset($val['Index']['Date'])) 
   { 
    $results[$key]['Index']['Date'] = $this->dateFormatAfterFind($val['Index']['Date']); 
   } 
  } 
  return $results; 
 } 
 
 function dateFormatAfterFind($dateString) 
 { 
  return date('d/m/Y', strtotime($dateString)); 
 } 
 
 function dateFormatBeforeSave($dateString) 
 { 
  $newDate = explode("/",$dateString); 
  return $newDate[2]."-".$newDate[1]."-".$newDate[0]; 
 } 
 
 function beforeSave($options = array() ) 
 { 
  if (!empty($this->data['Index']['Date'])) 
  { 
   $this->data['Index']['Date'] = $this->dateFormatBeforeSave($this->data['Index']['Date']); 
  }
  return true; 
 }


/**
 * Primary key field
 *
 * @var string
 */
	public $primaryKey = 'IndicesID';

/**
 * Display field
 *
 * @var string
 */
	public $displayField = 'IndicesID';

/**
 * Validation Rules
 *
 * @var $name = 'Index'
 */
	public $validate = array(
    	
    	'IndexName' => array(
    		'notempty' => array(
                'rule' => array('notempty'),
                'message' => 'Please input the name of the Index.'
        	),
    	),
		'Value' => array(
    		'notempty' => array(
                'rule' => array('notempty'),
        		'message' => 'Please input the Value.'
            ),
        ),  
        'ReturnValue' => array(
    		'notempty' => array(
                'rule' => array('notempty'),
        		'message' => 'Please input the Return Value.'
            ),
        ),  
        'AssignedPortfolios' => array(
    		'notempty' => array(
                'rule' => array('notempty'),
            ),
        ),  
        'Weighting' =>  array(
            'range' => array(
            'rule' => array('range', '0','101'),
                'message' => 'The weighting percentage can only be between 0 to 100.'
            ), //need to allow for empty too....
        ), 
        'OneMonthReturn' => array(
        	//'notempty' => array(
        	//	'rule' => array('notempty'),
        	//),
        ),
        'ThreeMonthReturn' => array(
        	//'notempty' => array(
        	//	'rule' => array('notempty'),
        	//),
        ),
        'SixMonthReturn' => array(
        	//'notempty' => array(
        	//	'rule' => array('notempty'),
        	//),
        ),
        'OneYearReturn' => array(
        	//'notempty' => array(
        	//	'rule' => array('notempty'),
        	//),
        ),
        'TwoYearReturn' => array(
        	//'notempty' => array(
        	//	'rule' => array('notempty'),
        	//),
        ),
        'ThreeYearReturn' => array(
        	//'notempty' => array(
        	//	'rule' => array('notempty'),
        	//),
        ),
        'FourYearReturn' => array(
        	//'notempty' => array(
        	//	'rule' => array('notempty'),
        	//),
        ),
        'FiveYearReturn' => array(
        	//'notempty' => array(
        	//	'rule' => array('notempty'),
        	//),
        ),
        'SinceInceptionReturn' => array(
        	//'notempty' => array(
        	//	'rule' => array('notempty'),
        	//),
        ),

     );
}
